var jsfiles = 0;
var jsfiles = 0;
/**
 * load js file with the filename specified and call callback function if present.
 * @param obj
 * obj = {};
 * obj.urlprefix: specified the path for the js file.
 * obj.filename: the filename  (example:  obj.filename = "/search.js?rev={%SEARCH_JS%}";)
 * obj.fn: callback function. (example:  obj.fn = function(jsfiles) {alert("hello" + jsfiles)}; )
 */

jQuery(function($) {
    if ($("#newmsgs") != null) {
        var curcolor = $("#newmsgs").css("color");
        window.setInterval(function() {
            $("#newmsgs").css("color", $("#newmsgs").css("color") == curcolor ? '#CCC' : curcolor);
            //$("#newmsgs").toggle();
        }, 500);
    }
    function aforseo(){
        $("a.aforseo").mouseover(function(){
            var href = $(this).attr("name");
            $(this).attr("href",href);
        });
        $("a.aforseo").click(function(){
            var href = $(this).attr("name");
            $(this).attr("href",href);
        });
    }
//    aforseo();
});

function loadjs(obj) {
    if (obj == null || obj.filename == null) {
        return false;
    }
    var opts = {};
    opts.id = jsfiles;
    if (obj.urlprefix == null) {
        obj.urlprefix = Globals.define.urlStatic + "/js";

    }
    if (obj.fn == null) {
        obj.fn = function(jsfiles) {
        }
    }
    if (!Globals.loader) {
        Globals.loader = new loaderClass();
    }

    opts.fn = obj.fn;
    var url = obj.urlprefix + obj.filename;
    Globals.loader.script(url, opts);
    jsfiles++;
}

var updateNewMsg = function(msgs) {
    $("div.header #newmsgs").remove();
    if (msgs > 0) {
        var tmpl = '<strong id="newmsgs">(' + msgs + ')</strong>';
        $("div.header #msg").append(tmpl);
    }
}

$(".aslink").hover(function() {
    $(this).addClass("aslinkhover");
}, function() {
    $(this).removeClass("aslinkhover");
});


function subSearch() {
    var labelforagent = "请输入经纪人编号、姓名或者用户名……";
    var labelforhouse = "请输入房源特征，地点或小区名……";
    $(".subsearch label").click(function() {
        $("#typebox").show();
    });
    $("#typebox li a").click(function() {
        $(this).parent().click();
        return false;
    });

    $("#typebox li").click(function() {
        var labeltext = $(this).text();
        var action = $(this).find("a").attr("href");
        $("#typebox").hide();
        $(".subsearch label").text(labeltext);
        $(".subsearch form").attr("action", action);
        if (labeltext == '搜经纪人') {
            $(".subsearch input.tx").val(labelforagent)
        } else {
            $(".subsearch input.tx").val(labelforhouse)
        }
        $(".subsearch input.tx").css("color", "#999");
    });
    $(".subsearch input.tx").focus(function() {
        if ($(".subsearch label").text() == '搜经纪人') {
            if ($(this).val() == labelforagent) {
                $(this).val("").css("color", "#000");
            }
        } else {
            if ($(this).val() == labelforhouse) {
                $(this).val("").css("color", "#000");
            }
        }
    });
    $(".subsearch input.tx").blur(function() {
        if ($(".subsearch label").text() == '搜经纪人') {
            if ($(this).val() == "") {
                $(this).val(labelforagent).css("color", "#999");
            }
        } else {
            if ($(this).val() == "") {
                $(this).val(labelforhouse).css("color", "#999");
            }
        }
    });
    $(".subsearch form .btn").click(function() {
        if ($(".subsearch label").text() == '搜经纪人') {
            if ($(".subsearch input.tx").val() == labelforagent || $(".subsearch input.tx").val().length == 0) {
                alert(labelforagent);
                return false;
            }
        } else {
            if ($(".subsearch input.tx").val() == labelforhouse || $(".subsearch input.tx").val().length == 0) {
                alert(labelforhouse);
                return false;
            }
        }
    });
    $("body").click(function(event) {
        if ($.nodeName(event.target, "label")) {
            return false;
        }
        $("#typebox").hide();
    })
}

function pathnav() {
    $(".path a:last").addClass("nohref");
}

function HomeClass() {
}
HomeClass.prototype = {
    loadestate:function() {
        loadjs({filename:"/estate.js?rev={%ESTATE_JS%}"});
    },
    notfound:function() {
        $(".estates ul:first").show();
        $(".tabs li:first").addClass("current");
        $(".tabs li:first").addClass("first");
        $(".tabs li").not(".more").hover(function() {
            var tabindex = $(".tabs li").index(this);
            $(".tabs li").removeClass("current");
            $(".estates ul").hide();
            $(this).addClass("current");
            $(".estates ul").eq(tabindex).show();
        });
        var keywords = $("input[name='keyword']").attr("value");
        $("input[name='keyword']").focus(function() {
            if ($(this).val() == keywords) {
                $(this).val("").css("color", "#000");
            }
        });
        $("input[name='keyword']").blur(function() {
            if ($(this).val() == "") {
                $(this).val(keywords).css("color", "#999");
            }
        });
        $("form").submit(function() {
            if ($("input[name='keyword']").val() == "" || $("input[name='keyword']").val() == keywords) {
                alert("请输入关键词");
                return false;
            }
        });
    },
    index:function() {
        alert(1);
        this.loadestate();
        $(".nav li").removeClass("up");
        $("#n_index").addClass("up");
        var keywords = "请输入房源特征，地点或小区名……";
        $("input[name='keyword']").focus(function() {
            if ($(this).val() == keywords) {
                $(this).val("").css("color", "#000");
            }
        });
        $("input[name='keyword']").blur(function() {
            if ($(this).val() == "") {
                $(this).val(keywords).css("color", "#999");
            }
        });
        $("#esf input.btn").click(function() {
            if ($("#esf input[name='keyword']").val() == keywords) {
                $("#esf input[name='keyword']").val("");
            }
        });
        $("#czf input.btn").click(function() {
            if ($("#czf input[name='keyword']").val() == keywords) {
                $("#czf input[name='keyword']").val("");
            }
        });
        $(".newrates li:last").css("border", "0");
        $(".footer").css("paddingTop", "0");
        var objs = Globals.objs;
        objs.renttab = $("li#tczf");
        objs.resaletab = $("li#tesf");
        objs.resalebox = $("div#esf");
        objs.rentbox = $("div#czf");
        objs.searchinput = $("input[name='keyword']");
        objs.renttab.click(function(e) {
            var objs = Globals.objs;
            setPostfix("_rent");
            objs.renttab.addClass("up");
            objs.rentbox.show();
            objs.resaletab.removeClass("up");
            objs.resalebox.hide();
        })
        objs.resaletab.click(function(e) {
            var objs = Globals.objs;
            setPostfix("");
            objs.resaletab.addClass("up");
            objs.resalebox.show();
            objs.renttab.removeClass("up");
            objs.rentbox.hide();
        });
        $(".estates ul:first").show();
        $(".tabs li:first").addClass("current");
        $(".tabs li:first").addClass("first");
        $(".tabs li").not(".more").hover(function() {
            var tabindex = $(".tabs li").index(this);
            $(".tabs li").removeClass("current");
            $(".estates ul").hide();
            $(this).addClass("current");
            $(".estates ul").eq(tabindex).show();
        });
        //loadjs({filename:"/home.js?rev={%HOME_JS%}"});
    },
    agentlist:function() {
        $(".nav li").removeClass("up");
        $("#n_agentlist").addClass("up");
        subSearch();
        pathnav();
        $(".usercard").hover(function() {
            $(".usercard").removeClass("hover");
            $(this).addClass("hover");
        }, function() {
            $(".usercard").removeClass("hover");
        });
    },
    login:function() {
        //IE下设定光标到文本框的最后面
        var utilityHandle = {
            setFocus:function(objFocusEven, values) {
                objFocusEven.focus();
                if ($.browser.msie) {
                    var txt = objFocusEven[0].createTextRange();
                    txt.moveStart('character', values);
                    txt.collapse(true);
                    txt.select();
                }
            }};
        var nick = $("#nick");
        var length = $("#nick").val().length;
        utilityHandle.setFocus(nick, length);
    }
}

function SearchClass() {
    $(".houses li").hover(function() {
        $(".houses li").removeClass("hover");
        $(this).addClass("hover");
    }, function() {
        $(".houses li").removeClass("hover");
    });
    $(".bykeywords a.sel").click(function() {
        return false;
    });
    subSearch();
}
function verifyinsearchpage() {
    var closeimg = '<img id="close" src="' + Globals.define.urlStatic + '/images/admin/close.gif" alt="" />';
    var tmpl = '<div class="verifybox" id="verifybox">' + '<h3>审核房源</h3>' + closeimg + '<div class="framebox"><iframe id="verifyiframe" name="verifyiframe" src=""></iframe></div></div>';
    $("body").append(tmpl);
    $(".goverify a.c").click(function() {
        var isie6 = $.browser.msie && ($.browser.version == "6.0") && !$.support.style;
        if (isie6) {
            alert("建议安装firefox");
        } else {
            var width = $(window).width();
            var height = $(window).height();
            var framewidth = $("#verifybox").width() + 20;
            var frameheight = $("#verifybox").height() + 20;
            var top = (height - frameheight) / 2;
            var left = (width - framewidth) / 2;
            var iframeurl = $(this).attr("href");
            $("#verifyiframe").attr("src", iframeurl);
            $("#verifybox").css("top", top).css("left", left).show();
            return false;
        }
    });
    $("#close").click(function() {
        $("#verifyiframe").attr("src", "");
        $(this).parent("div").hide();
        top.location.reload()
    });
}
function highqualinsearchpage() {
    var closeimg = '<img id="close" src="' + Globals.define.urlStatic + '/images/admin/close.gif" alt="" />';
    var tmpl = '<div class="verifybox" id="highqualbox">' + '<h3>审核房源</h3>' + closeimg + '<div class="framebox"><iframe id="highqualiframe" name="highqualiframe" src=""></iframe></div></div>';
    $("body").append(tmpl);
    $(".goverify a.h").click(function() {
        var isie6 = $.browser.msie && ($.browser.version == "6.0") && !$.support.style;
        if (isie6) {
            alert("建议安装firefox");
        } else {
            var width = $(window).width();
            var height = $(window).height();
            var framewidth = $("#verifybox").width() + 20;
            var frameheight = $("#verifybox").height() + 20;
            var top = (height - frameheight) / 2;
            var left = (width - framewidth) / 2;
            var iframeurl = $(this).attr("href");
            $("#verifyiframe").attr("src", iframeurl);
            $("#verifybox").css("top", top).css("left", left).show();
            return false;
        }
    });
    $("#close").click(function() {
        $("#verifyiframe").attr("src", "");
        $(this).parent("div").hide();
        top.location.reload()
    });
}
SearchClass.prototype = {
    loadestate:function() {
        loadjs({filename:"/estate.js?rev={%ESTATE_JS%}"})
    },
    resale:function() {
        this.loadestate();
        loadjs({filename:"/search.js?rev={%SEARCH_JS%}"});
        $(".nav li").removeClass("up");
        $("#n_resale").addClass("up");
        $("#name").focus();
        verifyinsearchpage();
        pathnav();
    },
    rent:function() {
        this.loadestate();
        loadjs({filename:"/search.js?rev={%SEARCH_JS%}"});
        $(".nav li").removeClass("up");
        $("#n_rent").addClass("up");
        $("#name").focus();
        verifyinsearchpage();
        pathnav();
    }
}

function viewpagetab() {
    var tag = $(".morenav li");
    var box = $(".moreinfo div.houseinfo");
    $(tag).click(function() {
        var tabindex = $(tag).index(this);
        $(tag).removeClass("up");
        $(this).addClass("up");
        if (tabindex == 0) {
            $(box).show("");
        } else {
            $(box).hide();
            $(box).eq(tabindex).show("");
        }
        ;
        return false;
    });
}

function ResaleClass() {
}


ResaleClass.prototype = {
    view:function() {
        subSearch()
        $(".nav li").removeClass("up");
        $("#n_resale").addClass("up");
        $(".description").bind("selectstart", function() {
            return false;
        }).bind('contextmenu', function() {
            return false;
        });
        viewpagetab();
        $(".newrates li:last").css("border", "none");
        var length = $("#mainMapBox").html.length;
        if (length < 2) {
            $("#mainMapBox").html("<p class='txc' style='padding:30px 0;'>该小区暂无地图信息</p>");
        }
    }
}

function RentClass() {
}

RentClass.prototype = {
    view:function() {
        subSearch()
        $(".nav li").removeClass("up");
        $("#n_rent").addClass("up");
        $(".description").bind("selectstart", function() {
            return false;
        }).bind('contextmenu', function() {
            return false;
        });
        viewpagetab();
        $(".newrates li:last").css("border", "none");
        var length = $("#mainMapBox").text.length;
        if (length < 2) {
            $("#mainMapBox").html("<p class='txc' style='padding:30px 0;'>该小区暂无地图信息</p>")
        }
    }
}

function AgentClass() {
    $("#listform tr").hover(function() {
        $("#listform tr").removeClass("hover");
        $(this).addClass("hover");
    }, function() {
        $("#listform tr").removeClass("hover");
    });
    $("#name").focus();
    if ($("#estatenameerrors").length > 0) {
        $(".estatenametips").hide();
    }
    $(".housenew tr:has('.errors')").addClass("haserror");
    $(".haserror:first").find("input:text,textarea").focus();

}

function alerterrors() {
    var errors = $("span.errors");
    if (errors.length == 0) {
        return;
    }
    var tips = "你提交的信息有错误，请检查重新填写！\n\n";
    var length = errors.length;
    var msg = "";
    for (var i = 0; i < length; i++) {
        var str = $(errors[i]).text();
        if (length > 1) {
            str = (i + 1) + "." + str;
        }
        msg += str;
        if (msg.length == 0) {
            continue;
        }
        msg += "\n\n";
    }
    alert(tips + msg);
}

function titlecount() {
    $("#title").keyup(function() {
        $("#titlecount").show();
        var titlevalue = $(this).attr("value");
        var titlelength = $(this).attr("value").length;
        var remain = 24 - titlelength;

        if (remain > 0) {
            $("#titlecount").html("还可以输入<strong>" + remain + "</strong>个字符");
        } else {
            $("#titlecount").html("<strong>标题已经超过限制了</strong>");
        }
    }).keydown(function() {
        $("#titlecount").show();
        var titlevalue = $(this).attr("value");
        var titlelength = $(this).attr("value").length;
        var remain = 24 - titlelength;

        if (remain > 0) {
            $("#titlecount").html("还可以输入<strong>" + remain + "</strong>个字符");
        } else {
            $("#titlecount").html("<strong>标题已经超过限制了</strong>");
        }
    }).blur(function() {
        if ($("#titlecount").html() == "<strong>标题已经超过限制了</strong>") {
            $("#titlecount").show();
        }
    });
}

function housesaved() {
    var radio = $("input:checked");
    $(radio).parents("li").addClass("ischecked");
    if (radio.length == 0) {
        $("input[type=radio]:first").attr("checked", "checked");
    }
    $(".phototiny img").each(function() {
        $(this).click(function() {
            $(this).next("p").find("input[type=radio]").attr("checked", true);
            $(".phototiny li").removeClass("ischecked");
            $(this).parent("li").addClass("ischecked");
        });
    });
    $(".phototiny form").submit(function() {
        if (radio.length == 0) {
            $("input[type=radio]:first").attr("checked", "checked");
        }
    });
}

AgentClass.prototype = {
    home:function() {
    },
    signup:function() {
        $("input:first").focus();
    },
    loadswfjs:function() {
        var obj = {};
        obj.filename = "/swfobject.js?rev={%SWFOBJECT_JS%}";
        var urlPrefix = Globals.define.urlPrefix;
        var urlStatic = Globals.define.urlStatic;
        var fileUploaderUrl = urlStatic + "/media/upload/FlexUploader.swf";
        var expressInstallUrl = null;//urlStatic + "/media/upload/expressInstall.swf";
        obj.fn = function(jsfiles) {
            swfobject.embedSWF(fileUploaderUrl, "swf_photo_layout_loc", "224", "26", "10.0.0", expressInstallUrl,
            {UploadUrl: urlPrefix + "/photo/uploadhp?category=layout"},
            {wmode:"transparent",allowscriptaccess :"always"}, {id:"swf_photo_layout"});
            swfobject.embedSWF(fileUploaderUrl, "swf_photo_inner_loc", "224", "26", "10.0.0", expressInstallUrl,
            {UploadUrl: urlPrefix + "/photo/uploadhp?category=inner" },
            {wmode:"transparent",allowscriptaccess :"always"}, {id:"swf_photo_inner"});

            swfobject.embedSWF(fileUploaderUrl, "swf_photo_community_loc", "224", "26", "10.0.0", expressInstallUrl,
            {UploadUrl : urlPrefix + "/photo/uploadhp?category=community"},
            {wmode:"transparent",allowscriptaccess :"always"}, {id:"swf_photo_community"});
        }
        loadjs(obj);
    },
    verify:function() {
        $("input[name=idnum]").focus();
        var obj = {};
        obj.filename = "/uploadagentphoto.js?rev={%UPAGENTPHOTO_JS%}";
        obj.fn = function(jsfiles) {
            agentphoto = new AgentPhotoClass();
        }
        loadjs(obj);
        loadjs({filename:"/broker.js?rev={%BROKER_JS%}"});
        loadjs({filename:"/locselector.js?rev={%LOCSELECTOR_JS%}"});
        var errfields = $("span.errors");
        if (errfields.length > 0) {
            $(errfields[0]).parent().find("input").focus();
        }
        alerterrors()

    },
    setting:function() {
        loadjs({filename:"/locselector.js?rev={%LOCSELECTOR_JS%}"});
        $("input[name=name]").focus();
    },
    getjsfiles:function(housetype) {
        var obj = {};
        obj.filename = "/estate.js?rev={%ESTATE_JS%}";
        obj.fn = function(jsfiles) {

            $("input#selectbtn").click(function(e) {
                getEstate();
            });
        }
        loadjs(obj);
        obj.filename = "/uploadhousephoto.js?rev={%UPHOUSEPHOTO_JS%}";
        obj.fn = function(jsfiles) {
            photoinit(housetype);
        }
        loadjs(obj);
        //        this.loadswfjs();
    },
    showexpire:function() {
        if ($("#tips").length > 0) {
            alert($("#tips").text());
        }
    },
    getagentjs:function() {
        loadjs({filename:"/agent.js?rev={%AGENT_JS%}"});
    },
    loadeditjs:function(housetype) {
        var obj = {};
        obj.filename = "/uploadhousephoto.js?rev={%UPHOUSEPHOTO_JS%}";
        obj.fn = function(jsfiles) {
            photoinit(housetype);
        }
        loadjs(obj);
        //        this.loadswfjs();
    },
    rentnew:function() {
        this.showexpire();
        this.getjsfiles("rent");
        alerterrors();
        titlecount();
        $(".facility").find("input:lt(3)").attr("checked", "checked");
        $("#equipall").toggle(
                function() {
                    $(this).text("全不选");
                    $("input[name=equipment.checked]").attr("checked", "checked");
                },
                function() {
                    $(this).text("全选");
                    $("input[name=equipment.checked]").attr("checked", "");
                }
                );
    },
    rentedit:function() {
        this.loadeditjs("rent");
        alerterrors();
        titlecount();
        $("#equipall").toggle(
                function() {
                    $(this).text("全不选");
                    $("input[name=equipment.checked]").attr("checked", "checked");
                },
                function() {
                    $(this).text("全选");
                    $("input[name=equipment.checked]").attr("checked", "");
                }
                );
    },
    rentsaved:function() {
        housesaved();
    },
    resalenew:function() {
        this.showexpire();
        this.getjsfiles("resale");
        alerterrors();
        titlecount();
    },
    resaleedit:function() {
        this.loadeditjs("resale");
        alerterrors();
        titlecount();
    },
    resalesaved:function() {
        housesaved();
    },
    resalelist:function() {
        this.getagentjs();
    },
    rentlist: function() {
        this.getagentjs();
    },
    rentunshelved:function() {
        this.getagentjs();
    },
    resaleunshelved:function() {
        this.getagentjs();
    },
    neworder:function() {
        loadjs({filename:"/neworder.js?rev={%NEWORDER_JS%}"});
    },
    confirm:function() {
        loadjs({filename:"/neworder.js?rev={%NEWORDER_JS%}"});
    },
    mycard:function() {
        loadjs({filename:"/neworder.js?rev={%NEWORDER_JS%}"});
    }
}

function UserClass() {
}

UserClass.prototype = {
    setting:function() {
        $("input[name=name]").focus();
    }
}

function AccountClass() {
}

function signupform() {
    $("input.tx").focus(function(event) {
        $("p").removeClass("current");
        $(this).parent("p").addClass("current");
    });
    $("input.tx").blur(function() {
        $("p").removeClass("current");
    });
    $("select").focus(function() {
        $("p").removeClass("current");
        $(this).parent("p").addClass("current");
    });
}
AccountClass.prototype = {
    agentsignup:function() {
        loadjs({filename:"/locselector.js?rev={%LOCSELECTOR_JS%}"});
        $("#signupform p:has('.errors')").addClass("haserror");
        $(".haserror:first").find("input:text").focus();
        signupform()
    },
    usersignup:function() {
        $("#signupform p:has('.errors')").addClass("haserror");
        $(".haserror:first").find("input:text").focus();
        signupform();
    },
    getpassword:function() {
        $("#email").focus();
    },
    password:function() {
        $("input[name=oldpasswd]").focus();
    }
}

function OrderClass() {
    loadjs({filename:"/neworder.js?rev={%NEWORDER_JS%}"});

}

OrderClass.prototype = {
    confirm:function() {
        var errors = $("p.errors").html();
        if (errors != null && errors.length > 0) {
            alert(errors);
        }
    }
}

function ReportClass() {
}

ReportClass.prototype = {
    result:function() {
        var source = $("#source").text();
        var houseid = $("#houseid").text();
        var url = Globals.define.urlPrefix + "/" + source + "/view/" + houseid;

        function jump(count) {
            window.setTimeout(function() {
                count--;
                if (count > 0) {
                    $('#num').attr('innerHTML', count);
                    jump(count);
                } else {
                    location.href = url;
                }
            }, 1000);
        }

        jump(5);
    }
}

function RateClass() {
    $(".nav li").removeClass("up");
    $("#n_agentlist").addClass("up");
    loadjs({filename:"/rate.js?rev={%RATE_JS%}"});
}

RateClass.prototype = {

    find:function() {
        $("input[name=code]").focus();
        $(":submit").click(function() {
            var pattern = /^([0-9]){3,8}$/;
            var value = $("#code").attr("value");
            var val = $.trim(value);
            $("#code").attr("value", val);
            if (!pattern.test(val)) {
                alert("请输入正确的经纪人编号：3-8位数字");
                return false;
            }
        });
        $("#close").click(function() {
            $(this).parent(".ratetips").hide();
        });
        var imgsrc1 = Globals.define.urlStatic + "/images/card2demo1.png"
        var imgsrc2 = Globals.define.urlStatic + "/images/card1demo1.png"
        $(".changeimg").toggle(function() {
            $(".imgdemo").attr("src", imgsrc2);
            $(".changeimg").text("我的卡是红色的？");
        }, function() {
            $(".imgdemo").attr("src", imgsrc1);
            $(".changeimg").text("我的卡是绿色的？");
        });
    },
    verifysecret:function() {
        $("input[name=secret]").focus();
        $(":submit").click(function() {
            var pattern = /^([0-9]){8,8}$/;
            var value = $("input[name=secret]").attr("value");
            var val = $.trim(value);
            $("#code").attr("value", val);
            if (!pattern.test(val)) {
                alert("请输入正确的评价验证码：8位数字");
                return false;
            }
        });
        $("#close").click(function() {
            $(this).parent(".ratetips").hide();
        });
        var imgsrc1 = Globals.define.urlStatic + "/images/card1demo2.png"
        var imgsrc2 = Globals.define.urlStatic + "/images/card2demo2.png"
        $(".changeimg").toggle(function() {
            $(".imgdemo").attr("src", imgsrc1);
            $(".changeimg").text("我的卡是红色的？");
        }, function() {
            $(".imgdemo").attr("src", imgsrc2);
            $(".changeimg").text("我的卡是绿色的？");
        });
    },
    create:function() {
        $("textarea").focus();
        $("input.button").click(function() {
            var value = $("textarea").val();
            if (value.length == 0) {
                alert("评论内容不能为空");
                return false;
            }
        });
    },
    save:function() {
        $("input[name='name']").focus();
    },
    edit:function() {
        $("textarea").focus();
        $("input.button").click(function() {
            var value = $("textarea").val();
            if (value.length == 0) {
                alert("评论内容不能为空");
                return false;
            }
        });
    },
    comment:function() {
        $("textarea").focus();
    }
}

function MessageClass() {
    $(".selall").toggle(
            function() {
                $(this).attr("checked", "checkbox");
                $("input[name=ids]").attr("checked", "checked");
            },
            function() {
                $(this).attr("checked", "checkbox");
                $("input[name=ids]").attr("checked", "");
            }
            );
}

MessageClass.prototype = {
    create:function() {
        $("#title").focus();
    }
}
function AgentprofileClass() {
    $(".nav li").removeClass("up");
    $(".houses li").hover(function() {
        $(".houses li").removeClass("hover");
        $(this).addClass("hover");
    }, function() {
        $(".houses li").removeClass("hover");
        s
    });
    $(".houses li").click(function(event) {
        if ($.nodeName(event.target, "a")) {
            return true;
        }
        if ($.nodeName(event.target, "img")) {
            return true;
        }
        else {
            var url = $(this).find("dt a").attr("href");
            window.open(url, "");
        }
    });

    verifyinsearchpage();
    highqualinsearchpage();
}

function FeedbackClass() {

}

FeedbackClass.prototype = {
    add:function() {
        $(".tx").focus(function() {
            $("tr").removeClass("current");
            $("cite").hide();
            $(this).siblings(".errors").hide();
            $(this).parent("td").parent("tr").addClass("current");
            $(this).siblings("cite").show();

        });
    }
}

function AccessoryClass() {
}

AccessoryClass.prototype = {
    calc:function() {
        loadjs({filename:"/dkcalc.js?rev={%DKCALC_JS%}"});
    }
}

function tablestyleClass() {
    $(".listbox tr:even").addClass("odd");
    $(".listbox tr").hover(function() {
        $(".listbox tr").removeClass("hover");
        $(this).addClass("hover");
    }, function() {
        $(".listbox tr").removeClass("hover");
    });
    $(".listbox tr").click(function() {
        $(".listbox tr").removeClass("cur");
        $(this).addClass("cur");
    });
}


function AdminClass() {
    tablestyleClass();
    $(".menu > h4").each(function(i){
        this.onclick=function(){
            $(".menu > ul:eq("+i+")").toggle();
            return false;
        };
    });
}

function highligth() {
    var areamin = 30;
    var areamax = 300;
    var pricemin = 8000;
    var pricemax = 50000;
    var rentmin = 500;
    var rentmax = 50000;

    var area = $("li.area span");
    var price = $("li.price span");
    var rent = $("li.rent span");

    if ($(".rent").length == 0) {
        if (area.text() < areamin || area.text() > areamax) {
            $(area).parent("li").addClass("highlight");
        }
        if (price.text() < pricemin || price.text() > pricemax) {
            $(price).parent("li").addClass("highlight");
        }
    } else {
        if (rent.text() < rentmin || rent.text() > rentmax) {
            $(rent).parent("li").addClass("highlight");
        }
    }

}

AdminClass.prototype = {
    edmphotolist:function() {
        var keywords = "这里写备注……";
        $("input[name='desc']").val(keywords).css("color", "#999");
        $("input[name='desc']").focus(function() {
            if ($(this).val() == keywords) {
                $(this).val("").css("color", "#000");
            }
        });
        $("input[name='desc']").blur(function() {
            if ($(this).val() == "") {
                $(this).val(keywords).css("color", "#999");
            }
        });
        $("input[name='subbtn']").click(function(){
            if ($("input[name='desc']").val() == keywords) {
                $("input[name='desc']").val("").css("color", "#000");
            }
        });
    },
    edmnew:function() {
        $(".jtbcEditorDiv").css({width:"900px",height:"450px"});
        $(".jtbcEditorIframe").css({height:"422px"});
    },
    ccphotolist:function() {
        loadjs({filename:"/admin.js?rev={%ADMIN_JS%}", fn: function() {
            var estateop = Globals.objs.estateop = new EstateOp();
            $("input#findestateid").click(function(event) {
                Globals.objs.estateop.getEstateId();
            });
            photocntinit();
            photoProcessInit("comm");
        }});
        loadjs({filename:"/jquery.hotkeys.js?rev={%HOTKEYS_JS%}", fn: function() {
            $.hotkeys.add('k', function() {
                var delbtn = $("input.del:first");
                delbtn.click();
                $("li#notify").html("删除成功").show();
                $("li#notify").fadeOut(600);
            });
            $.hotkeys.add('j', function() {
                var addbtn = $("input.add:first");
                addbtn.click();
                $("li#notify").html("添加成功").show();
                $("li#notify").fadeOut(600);
            });
        }});
        $(".ccphotolist li img").click(function() {
            var largesrc = $(this).attr("title");
            var actadd = $(this).parent("li").find(".add").attr("href");
            var actdel = $(this).parent("li").find(".del").attr("href");
            $(".largebox").show();
            $(".largephoto").attr("src", largesrc);
            $(".largebox .add").attr("href", actadd);
            $(".largebox .del").attr("href", actdel);
        });
        $(".close").click(function() {
            $(".largebox").hide();
        });
        $(".listbox .estateid").each(function() {
            var ids = $(this).attr("id");
            if ($(".listbox [id=" + ids + "]").length > 1) {
                $(".listbox [id=" + ids + "]").parent("tr").hide().eq(0).show();
            }
        });
    },
    layoutlist:function() {
        loadjs({filename:"/admin.js?rev={%ADMIN_JS%}", fn: function() {
            var estateop = Globals.objs.estateop = new EstateOp();
            $("input#findestateid").click(function(event) {
                Globals.objs.estateop.getEstateId();
            });
            photocntinit();
            photoProcessInit("layout");
        }});
        loadjs({filename:"/jquery.hotkeys.js?rev={%HOTKEYS_JS%}", fn: function() {
            $.hotkeys.add('k', function() {
                var delbtn = $("input.del:first");
                delbtn.click();
                $("li#notify").html("删除成功").show();
                $("li#notify").fadeOut(600);
            });
            $.hotkeys.add('j', function() {
                var addbtn = $("input.add:first");
                addbtn.click();
                $("li#notify").html("添加成功").show();
                $("li#notify").fadeOut(600);
            });
        }});
    },
    hotlist:function() {
        $("input[name=btnadd]").click(function() {
            $(".addform").show();
        })
        $(".close").click(function() {
            $(".addform").hide();
        })
    },
    loadadminjs:function() {
        loadjs({filename:"/admin.js?rev={%ADMIN_JS%}"});
    },
    getlocservice:function() {
        var obj = {};
        obj.filename = "/admin.js?rev={%ADMIN_JS%}";
        obj.fn = function(jsfiles) {
            initLocation();
        }
        loadjs(obj);
    },
    saleslist:function() {
        this.getlocservice();
        $("#newbind").click(function() {
            $("#bindbox").show();
        });
        $(".add a").click(function() {
            $("#bindbox").show();
            var ids = $(this).attr("id");
            $("input[name=id]").attr("value", ids);
        });
    },
    agentverify:function() {
        var obj = {};
        obj.filename = "/admin.js?rev={%ADMIN_JS%}";
        obj.fn = function(jsfiles) {
            initAgentVerify();
        }
        loadjs(obj);
    },
    agentmngt:function() {
        loadjs({filename:"/locselector.js?rev={%LOCSELECTOR_JS%}"});
        loadjs({filename:"/sms.js?rev={%SMS_JS%}",
            fn:function() {

                //receivers.length
                $("input#sendsms").click(function() {
                    var pan = $("div#smspan");
                    if(pan.css("display").toLowerCase() == 'none') {
                        pan.show();
                    } else {
                        pan.hide();
                        return true;
                    }
                    var receivers = $("input[type='checkbox']:checked");
                    var mobiles = [];
                    var label = "";
                    for (i = 0; i < receivers.length; i++) {
                        var r = receivers[i];
                        var tr = $(r).parents("tr");
                        var str = $("span.mobile", tr).html();
                        mobiles.push(str);
                        label += str + " ";
                    }
                    $("textarea#sms_receivers").val(label);
                    smsobj.setMobiles(mobiles);
                    
                })
//                $("input#sms_confirm").click(function() {
//                        sendsms();
//                    })
            }
        });
        $("#outexcel").click(function(){
            $("input[name=act]").val(1)
            $("form[name=fm]").submit();
            $("input[name=act]").val(0)
        });
    },
    agentExpiredLoginStat:function() {
        loadjs({filename:"/locselector.js?rev={%LOCSELECTOR_JS%}"});

    },
    houseverify:function() {
        var obj = {};
        obj.filename = "/admin.js?rev={%ADMIN_JS%}";
        obj.fn = function(jsfiles) {
            initHouseVerify();
            var beds_selector = "code#beds";
            var estate_selector = "code#estateid";
            avgpriceinit(estate_selector, beds_selector);
        }
        loadjs(obj);
        var obj = {};
        obj.filename = "/estatename.js?rev={%ESTATENAME_JS%}";
        obj.fn = function(jsfiles) {
            handleClick();
            //
        }
        loadjs(obj);
        highligth();

    },

    exportlist:function() {

        $("a.bind").click(function() {
            var rpid = $(this).attr("id");
            var count = $(this).attr("title");
            $(".bindform").show();
            $("input[name=begin]").focus();
            $("input[name=id]").attr("value", rpid);
            $("input[name=count]").attr("value", count);
        });
        $("#selall").toggle(
                function() {
                    $(this).attr("checked", "checkbox");
                    $("input[name=ids]").attr("checked", "checked");
                },
                function() {
                    $(this).attr("checked", "checkbox");
                    $("input[name=ids]").attr("checked", "");
                }
                );
        $("#close").click(function() {
            $(".bindform").hide();
        });
        $("#sycnall").click(function() {
            var url = Globals.define.urlPrefix + "/admin/card/sync?type=1";
            location.href = url;
        });
    },

    cardorderlist:function() {
        $("a.cardok").click(function() {
            var rpid = $(this).parent("td").siblings("#rpid").text();
            var brand = $(this).parent("td").siblings("#fullbrand").text();
            var addr = $(this).parent("td").siblings("#fulladdr").text();
            var mobile = $(this).parent("td").siblings("#mobile").text();
            var price = parseInt($("#price_" + rpid).attr("value"));
            price = parseInt(price / 100);

            var type = $(this).attr("title");
            $(".bindform").show();
            $("input[name=id]").attr("value", rpid);
            $("input[name=fullbrand]").attr("value", brand);
            $("input[name=fulladdr]").attr("value", addr);
            $("input[name=mobile]").attr("value", mobile);
            $("span[name=pricespan]").text(price);
            $("input[name=finalprice]").attr("value", price);
            if (type == 0) {
                $(".payoption").html("");
                $(".memo").val("淘房卡试用");
            }
        });
        $("a.delete").click(function() {
            var rpid = $(this).parent("td").siblings("#rpid").text();
            $(".deleteform").show();
            $("input[id=deleteorderid]").attr("value", rpid);
        });
        $(".close").click(function() {
            $(".bindform").hide("");
            $(".deleteform").hide("");
            $(".deleteconfirmform").hide("");
            $(".addform").hide("");
        });

        $("a.deleteconfirm").click(function() {
            var rpid = $(this).parent("td").siblings("#rpid").text();
            $("input[id=deleteconfirmorderid]").attr("value", rpid);
            $("input[id=deleteconfirmbox]").attr("checked", false);
            $("input[id=deleteconfirmcmd]").attr("disabled", true);
            $(".deleteconfirmform").show();
        });

        $("a.addinvoice").click(function() {
            var rpid = $(this).parent("td").siblings("#rpid").text();
            var price = parseInt($("#price_" + rpid).attr("value"));
            var finalprice = parseInt($("#finalprice_" + rpid).attr("value"));
            price = parseInt(price / 100);
            finalprice = parseInt(finalprice / 100);
            $("input[name=orderid]").attr("value", rpid);
            $("span[name=orderidspan]").text(rpid);
            $("span[name=pricespan]").text(price);
            $("input[name=finalprice]").attr("value", finalprice);
            $(".addform").show();
        });
    },
    cardapplylist:function() {
        $("a.cardok").click(function() {
            var rpid = $(this).parent("td").siblings("#rpid").text();
            var brand = $(this).parent("td").siblings("#fullbrand").text();
            var addr = $(this).parent("td").siblings("#fulladdr").text();
            $(".bindform").show();
            $("input[name=id]").attr("value", rpid);
            $("input[name=fullbrand]").attr("value", brand);
            $("input[name=fulladdr]").attr("value", addr);
        });
        $("#close").click(function() {
            $(".bindform").hide("");
        });
    },

    invoicelist:function() {
        $("a.cardok").click(function() {
            var invoiceid = $(this).parent("td").siblings("#invoiceid").text();
            var title = $(this).parent("td").siblings("#invoicetitle").text();
            var price = parseInt($("#price_" + invoiceid).attr("value"));
            price = parseInt(price / 100);

            $("input[name=id]").attr("value", invoiceid);
            $("span[name=idspan]").text(invoiceid);
            $("span[name=pricespan]").text(price);
            $("span[name=titlespan]").text(title);

            $(".bindform").show();
        });
        $("a.delete").click(function() {
            var invoiceid = $(this).parent("td").siblings("#invoiceid").text();
            var title = $(this).parent("td").siblings("#invoicetitle").text();
            var price = parseInt($("#price_" + invoiceid).attr("value"));
            price = parseInt(price / 100);

            $("input[name=id]").attr("value", invoiceid);
            $("span[name=idspan]").text(invoiceid);
            $("span[name=pricespan]").text(price);
            $("span[name=titlespan]").text(title);

            $(".deleteform").show();
        });

        $("a.merge").click(function() {
            var boxes = document.getElementsByName("mid");
            var ids = [];
            var mids = "";
            var newprice = 0;
            var newtitle = "";
            for (var i = 0; i < boxes.length; i++) {
                var box = boxes[i];
                if (box.checked) {
                    var id = box.value;
                    ids[ids.length] = id;
                    mids += "<input type='hidden' name='id' value='" + id + "'/>";

                    var price = parseInt($("#price_" + id).attr("value"));
                    price = parseInt(price / 100);
                    newprice += price;

                    newtitle = $("#title_" + id).attr("value");
                }
            }
            if (ids.length < 2) {
                alert("请至少选择两个想要合并的发票");
                return;
            }

            $("#mergeidspan").html(mids);

            $("span[name=idspan]").text(ids.join(", ") + "(共" + ids.length + "个)");
            $("span[name=pricespan]").text(newprice);
            $("#newtitle").attr("value", newtitle);

            $(".addform").show();
        });
        $(".close").click(function() {
            $(".bindform").hide();
            $(".deleteform").hide();
            $(".addform").hide();
        });
    },
    financeAccountorderlist:function() {
        $("a.cardok").click(function() {
            var orderid = $(this).parent("td").siblings("#orderid").text();
            $("input[name=orderid]").attr("value", orderid);

            var price = parseInt($("#price_" + orderid).attr("value"));
            var finalprice = parseInt($("#finalprice_" + orderid).attr("value"));
            price = parseInt(price / 100);
            finalprice = parseInt(finalprice / 100);

            $("span[name=orderidspan]").text(orderid);
            $("span[name=pricespan]").text(price);
            $("span[name=finalpricespan]").text(finalprice);
            
            $("input[name=finalprice]").attr("value", finalprice);

            $("input[name=memo]").attr("value", $(this).parent("td").siblings("#remark").text());

            var paytype = $("#paytype_" + orderid).attr("value");
            //$("input[id=paytype" + paytype + "]").attr("checked", true);
            $("span[name=paytype]").hide();
            $("span[id=paytype" + paytype + "]").show();            

            $(".bindform").show();
        });
        $("a.delete").click(function() {
            var orderid = $(this).parent("td").siblings("#orderid").text();
            $("input[name=orderid]").attr("value", orderid);

            var price = parseInt($("#price_" + orderid).attr("value"));
            var finalprice = parseInt($("#finalprice_" + orderid).attr("value"));
            price = parseInt(price / 100);
            finalprice = parseInt(finalprice / 100);

            $("span[name=orderidspan]").text(orderid);
            $("span[name=pricespan]").text(price);
            $("span[name=finalpricespan]").text(finalprice);

            $("input[name=finalprice]").attr("value", finalprice);

            $(".deleteform").show();
        });
        $(".close").click(function() {
            $(".bindform").hide();
            $(".deleteform").hide();
        });
    },

    financeCardorderlist:function() {
        $("a.cardok").click(function() {
            var orderid = $(this).parent("td").siblings("#orderid").text();
            $("input[name=orderid]").attr("value", orderid);

            var price = parseInt($("#price_" + orderid).attr("value"));
            var finalprice = parseInt($("#finalprice_" + orderid).attr("value"));
            price = parseInt(price / 100);
            finalprice = parseInt(finalprice / 100);

            $("span[name=orderidspan]").text(orderid);
            $("span[name=pricespan]").text(price);
            $("span[name=finalpricespan]").text(finalprice);
            $("input[name=finalprice]").attr("value", finalprice);

            $("input[name=memo]").attr("value", $(this).parent("td").siblings("#remark").text());
            var paytype = $("#paytype_" + orderid).attr("value");
            //$("input[id=paytype" + paytype + "]").attr("checked", true);
            $("span[name=paytype]").hide();
            $("span[id=paytype" + paytype + "]").show();

            $(".bindform").show();
        });
        $("a.delete").click(function() {
            var orderid = $(this).parent("td").siblings("#orderid").text();
            $("input[name=orderid]").attr("value", orderid);

            var price = parseInt($("#price_" + orderid).attr("value"));
            var finalprice = parseInt($("#finalprice_" + orderid).attr("value"));
            price = parseInt(price / 100);
            finalprice = parseInt(finalprice / 100);

            $("span[name=orderidspan]").text(orderid);
            $("span[name=pricespan]").text(price);
            $("span[name=finalpricespan]").text(finalprice);

            $("input[name=finalprice]").attr("value", finalprice);

            $(".deleteform").show();
        });
        $(".close").click(function() {
            $(".bindform").hide();
            $(".deleteform").hide();
        });
    },
    accountorderlist:function() {
        $("a.cardok").click(function() {
            var orderid = $(this).parent("td").siblings("#orderid").text();
            var price = parseInt($("#price_" + orderid).attr("value"));
            price = parseInt(price / 100);
            $("input[name=orderid]").attr("value", orderid);
            $("input[name=sendmonth]").attr("value", $("#sendmonth_" + orderid).attr("value"));
            $("input[name=sendday]").attr("value", $("#sendday_" + orderid).attr("value"));
            $("input[name=cardcount]").attr("value", $("#cardcount_" + orderid).attr("value"));
            $("span[name=pricespan]").text(price);
            $("input[name=finalprice]").attr("value", price);
            $(".bindform").show();
        });
        $("a.delete").click(function() {
            var orderid = $(this).parent("td").siblings("#orderid").text();
            $("input[name=orderid]").attr("value", orderid);
            $("span#order").text(orderid);
            $(".deleteform").show();
        });
        $(".close").click(function() {
            $(".bindform").hide();
            $(".deleteform").hide();
            $(".addform").hide();
        });
        $("a.addinvoice").click(function(){
            var rpid = $(this).parent("td").siblings("#orderid").text();
            var price = parseInt($("#price_" + rpid).attr("value"));
            var finalprice = parseInt($("#finalprice_" + rpid).attr("value"));
            price = parseInt(price / 100);
            finalprice = parseInt(finalprice / 100);
            $("input[name=orderid]").attr("value", rpid);
            $("span[name=orderidspan]").text(rpid);
            $("span[name=pricespan]").text(price);
            $("input[name=finalprice]").attr("value", finalprice);
            $(".addform").show();
        });
    },
    accountorderverifylist:function() {
        $("a.cardok").click(function() {
            var orderid = $(this).parent("td").siblings("#orderid").text();
            var agentname = $(this).parent("td").siblings("#agentname").text();
            var orderprice = $(this).parent("td").siblings("#orderprice").text();
            $("input[name=orderid]").attr("value", orderid);
            $("span#order").text(agentname + "的订单" + orderid);
            $("span#orderPricePane").text(orderprice);
            $(".bindform").show();
        });
        $("a.delete").click(function() {
            var orderid = $(this).parent("td").siblings("#orderid").text();
            var agentname = $(this).parent("td").siblings("#agentname").text();
            $("input[name=orderid]").attr("value", orderid);
            $("span#orders").text(agentname + "的订单" + orderid);
            $(".deleteform").show();
        });
        $(".close").click(function() {
            $(".bindform").hide();
            $(".deleteform").hide();
        });
    },
    rateBadRateList:function() {
        $("a.delete").click(function() {
            var rateid = $(this).parent("td").siblings("#rateid__").text();
            var agentname = $(this).parent("td").siblings("#agentname__").text();
            $("input[name=rateid]").attr("value", rateid);
            $("span#agentname").text(agentname);
            $(".deleteform").show();
        });
        $(".close").click(function() {
            $(".deleteform").hide();
        });
    },
    cardSaleslist:function() {
        $("a.activate").click(function() {
            var receiptid = $(this).parent("td").siblings("#receiptid__").text();
            var agentname = $(this).parent("td").siblings("#agentname__").text();
            $("input[name=id]").attr("value", receiptid);
            $("span#agentname").text(agentname);
            $("span#receiptid").text(receiptid);

            $(".bindform").show();
        });
        $(".close").click(function() {

            $(".bindform").hide();
        });
    },
    paymentprocess:function() {
        var obj = {};
        obj.filename = "/ui.datepicker.js";
        obj.fn = function(jsfiles) {
            $("input[name=date]").datepicker();
        }
        loadjs(obj);
        loadjs({filename:"/ui.datepicker-zh-CN.js"});
    },
    locationstats:function() {
        var obj = {};
        obj.filename = "/ui.datepicker.js";
        obj.fn = function(jsfiles) {
            $("input[name=date]").datepicker();
        }
        loadjs(obj);
        loadjs({filename:"/ui.datepicker-zh-CN.js"});
    },
    salesdetail:function() {
        var obj = {};
        obj.filename = "/ui.datepicker.js";
        obj.fn = function(jsfiles) {
            $("input[name=startdate]").datepicker();
            $("input[name=enddate]").datepicker();
        }
        loadjs(obj);
        loadjs({filename:"/ui.datepicker-zh-CN.js"});
    },
    rateverify:function() {
        $(".close").click(function() {
            $(this).parent("form").hide();
        });
        $(".verify").click(function() {
            $(".badrateverify").hide();
            $(this).next("form").show();
        });
    },
    changeType:function() {
        for (var i = 0; i < 4; i++) {
            $("a[id=switch" + i + "]").click(function() {
                var salesvp = $("p.t").attr("id");
                if (salesvp == 'false' && this.id != "switch0") {
                    alert("你没有权限进行灵活延期");
                    return;
                }

                for (var k = 0; k < 4; k++) {
                    if (this.id == ("switch" + k)) {
                        $("a[id=switch" + k + "]").addClass("up");
                        $("div[id=tab" + k + "]").show();
                    } else {
                        $("a[id=switch" + k + "]").removeClass("up");
                        $("div[id=tab" + k + "]").hide();
                    }
                }
            });
        }
    },
    brokerlist:function() {
        loadjs({filename:"/locselector.js?rev={%LOCSELECTOR_JS%}"});
        loadjs({filename:"/broker.js?rev={%BROKER_JS%}"});
    },
    layoutadmin:function() {
        $("#largepic").append('<img />');
        $(".sphoto").click(function(e) {
            var node = $(e.target);
            if (!$.nodeName(e.target, "a")) {
                node = node.parent();
            }
            var imgsrc = node.attr("href");
            var ccphotolist = $("div.ccphotolist");
            var offset = node.offset();
            var offset2 = ccphotolist.offset();
            $("#largepic img").attr("src", imgsrc);
            //$("#largepic").css({'left':(offset.left - offset2.left), 'top':(offset.top-offset2.top)}).show();
            $("#largepic").css({'left':(offset2.left + 300), 'top':(offset2.top - 100)}).show();
            return false;
        });
        $("#largepic").click(function(event) {
            $("#largepic").hide();
        });
    }
}

function EstateClass() {
    tablestyleClass();
    SearchClass();
    pathnav();
    $(".nav li").removeClass("up");
    $("#n_estate").addClass("up");
}

EstateClass.prototype = {
    loadlocjs:function() {
        loadjs({filename:"/locselector.js?rev={%LOCSELECTOR_JS%}",fn:function(){
            if ($("code#lastblockid").length > 0) {
                var blockid = $("code#lastblockid").html();
                invokeGetEstates(blockid);
            }
            
        }});
    },
    verifyreq: function() {
        this.loadlocjs();
    },
    verify:function() {
        this.loadlocjs();
    },
    edit:function() {
        this.loadlocjs();
    },
    resalelist:function() {
        loadjs({filename:"/search.js?rev={%SEARCH_JS%}"});
        $(".houses li").hover(function() {
            $(".houses li").removeClass("hover");
            $(this).addClass("hover");
        }, function() {
            $(".houses li").removeClass("hover");
        });
        verifyinsearchpage();
    },
    rentlist:function() {
        loadjs({filename:"/search.js?rev={%SEARCH_JS%}"});
        $(".houses li").hover(function() {
            $(".houses li").removeClass("hover");
            $(this).addClass("hover");
        }, function() {
            $(".houses li").removeClass("hover");
        });
        verifyinsearchpage();
    },
    commlist:function() {
        photoview();
    },
    layoutlist:function() {
        photoview();
    },
    search:function(){
        loadjs({filename:"/search.js?rev={%SEARCH_JS%}"});
    }
}

function BrokerClass() {
}

BrokerClass.prototype = {
    verify:function() {
        loadjs({filename:"/locselector.js?rev={%LOCSELECTOR_JS%}"});
    },
    reassign:function() {
        loadjs({filename:"/locselector.js?rev={%LOCSELECTOR_JS%}"});
        loadjs({filename:"/broker.js?rev={%BROKER_JS%}"});
    }
}

function ForumClass() {
    $(".nav li").removeClass("up");
    $("#n_forum").addClass("up");

}

function valid() {
    $("input:submit").click(function() {
        var title = $("input[name=title]").val();
        var topicbody = $("input[name=body]").val();
        var titleerr = "";
        var bodyerror = "";
        if (title.length == 0) {
            titleerr = "帖子标题不能为空\n";
        }
        if (title.length > 30) {
            titleerr = "帖子标题不能超过30个汉字\n";
        }
        if (topicbody.length < 0) {
            bodyerror = "内容不能为空";
        }
        if (title.length == 0 || title.length > 30 || topicbody.length < 11) {
            alert(titleerr + bodyerror);
            return false;
        }

    });

}

function photoview() {
    var width = $(document).width();
    var height = $(window).height();
    var framewidth = $(".viewbox").width() + 20;
    var frameheight = $(".viewbox").height();
    var top = (height - frameheight) / 2;
    var left = (width - framewidth) / 2;
    var count = $(".photolist li").length;
    var last = $(".photolist li").eq(count - 1);
    var first = $(".photolist li").eq(0);
    $("#close").click(function() {
        $(".viewbox").hide();
        $(".photolist li").removeClass("current");
    });
    $(".photolist a.showlarge").click(function() {
        $(".photolist li").removeClass("current");
        $(this).parent().addClass("current");
        $(".viewbox img.photo_m").attr("src", "");
        var src = $(this).attr("href");
        var resaleurl = $(this).parent().find("#resaleurl").text();
        var renturl = $(this).parent().find("#renturl").text();
        $(".viewbox").show();
        $(".viewbox ").css("top", top).css("left", left);
        $(".viewbox img.photo_m").attr("src", src);
        $("#showlarge").attr("href", src);
        $("#next").show();
        $("#prev").show();
        $("#goresale").attr("href", resaleurl);
        $("#gorent").attr("href", renturl);
        if ($(last).hasClass("current")) {
            $("#next").hide();
            $("#prev").show();
        }
        if ($(first).hasClass("current")) {
            $("#next").show();
            $("#prev").hide();
        }
        return false;
    });
    $("#next").click(function() {
        $("#prev").show();
        var nsrc = $(".current").next("li").find("a").attr("href");
        var nresaleurl = $(".current").next("li").find("#resaleurl").text();
        var nrenturl = $(".current").next("li").find("#renturl").text();
        $("#goresale").attr("href", nresaleurl);
        $("#gorent").attr("href", nrenturl);
        $(".current").next("li").addClass("current");
        $(".current").eq(0).removeClass("current");
        if ($(last).hasClass("current")) {
            $("#next").hide();
        }
        $(".viewbox img.photo_m").attr("src", nsrc);
        $("#showlarge").attr("href", nsrc);
    });
    $("#prev").click(function() {
        $("#next").show();
        var psrc = $(".current").prev("li").find("a").attr("href");
        var presaleurl = $(".current").prev("li").find("#resaleurl").text();
        var prenturl = $(".current").prev("li").find("#renturl").text();
        $("#goresale").attr("href", presaleurl);
        $("#gorent").attr("href", prenturl);
        $(".current").prev("li").addClass("current");
        $(".current").eq(1).removeClass("current");
        if ($(first).hasClass("current")) {
            $("#prev").hide();
        }
        $(".viewbox img.photo_m").attr("src", psrc);
        $("#showlarge").attr("href", psrc);
    });
}

ForumClass.prototype = {
    board:function() {
        $("tr").hover(function() {
            $(this).addClass("hover").find(".topicaction").show();
        },
                function() {
                    $(this).removeClass("hover").find(".topicaction").hide();
                });
    },
    boardlist:function() {
        $(".boardlist tr:gt(0)").hover(function() {
            $(this).addClass("hover").find(".boardact").show();
        }, function() {
            $(this).removeClass("hover").find(".boardact").hide();
        });
        $(".agentverifiedlist dt a").click(function() {
            if ($("code#isnotverified").length > 0) {
                alert("你还没有通过身份认证，不能进入该版块");
                return false;
            }
        });

    },
    topic:function() {
        var imgwidth = $(".postbody img").attr("width");
        var imgpath = $(".postbody img").attr("src");
        if (imgwidth > 500) {
            $(".postbody img").attr("width", "500");
            $(".postbody img").wrap("<a href='' alt='查看原图'></a>");
            $(".postbody a[alt='查看原图']").attr("href", imgpath).attr("target", "new");
        }
    },
    edittopic:function() {
        $(".showupload a").click(function() {
            $(".oldpic").hide();
            $(".uoload").show();
            $("input[name=fileid]").attr("value", "0");
        });
    },
    editpost:function() {
        $(".showupload a").click(function() {
            $(".oldpic").hide();
            $(".uoload").show();
            $("input[name=fileid]").attr("value", "0");
        });
    },
    topic:function() {
        $(".replylink").click(function() {
            var author = $(this).attr("id");
            var floor = $(this).attr("title");
            var replycontent = "<p><b>回复" + floor + "楼作者" + author + "：</b></p>"
                    + "<p><br></p>";
            nEditor.tInstance.document.body.innerHTML = replycontent;
        });
    }
}

function ManagerClass() {
    loadjs({filename:"/manager.js?rev={%LOCSELECTOR_JS%}"});
}

ManagerClass.prototype = {
}

function ToolClass() {
}

ToolClass.prototype = {
    sendsms:function() {
        $("ul a").click(function(e) {
            var node = $(e.target);
            var nicks = $("input[name=nicks]").val();
            var newnick = node.attr("id");
            $("input[name=nicks]").val(nicks == "" ? newnick : nicks + ";" + newnick);
        })
    }

}

//请勿删除下面的代码 meecheng
//    applytest:function() {
//        $("dl:first").addClass("first");
//        $("dl").hover(function() {
//            $("dl").removeClass("hover");
//            $(this).addClass("hover");
//        },function(){
//            $("dl").removeClass("hover");
//        });
//        $("input#done").click(function() {
//            //选择提的答案在这里定义
//            var answer = [ "A", "B", "C", "B", "B", "C", "C", "C"];
//            var dls = $("dl");
//            var result = true;
//            for (i = 0; i < dls.length; i++) {
//                var value = $(dls[i]).find("input:checked").val();
//                if (value != answer[i]) {
//                    result = false;
//                    $(dls[i]).addClass("wrong");
//                } else {
//                    $(dls[i]).removeClass("wrong").addClass("right");
//                }
//            }
//            if (result) {
//                alert("恭喜你，全部正确。");
//                var gourl = Globals.define.urlPrefix + '/agent/applytest?result=ok';
//                document.location.href = gourl;
//            }
//            else {
//                alert("有错误哦。请重新选择有错误提示的题目");
//
//            }
//        });
//
//    }

